<template>
  <div class="setContent">
    <div class="content">
      <div class="cTitle">
        <h3><span>个人设置</span></h3>
      </div>
      <ul class="tabs">
        <li :class="setIndex === 1 ? 'active' : ''" @click="setIndex = 1"><a><em>基本设置</em></a></li>
        <!-- <li :class="setIndex === 2 ? 'active' : ''" @click="setIndex = 2"><a><em>绑定设置</em></a></li>
        <li :class="setIndex === 3 ? 'active' : ''" @click="setIndex = 3"><a><em>隐私设置</em></a></li> -->
      </ul>
      <form action="#">
        <div class="frmBase">
          <div class="frm">
            <div class="item">
              <label>昵称：</label>
              <input type="text" class="txt" v-model="form.name" maxlength="30">
            </div>
            <div class="frmtext">
              <label class="lab">介绍:</label>
              <div class="arear">
                <textarea id="sign" v-model="form.signture"></textarea>
                <span class="numCount">300字</span>
              </div>
            </div>
            <div class="area">
              <label class="chooseArea">地区：</label>
              <div class="Region">
                <input type="text" class="txt" v-model="form.position" maxlength="30" />
              </div>
            </div>
            <div class="savebtn">
              <el-button type="primary" @click="onSave">保存</el-button>
            </div>
            <div class="changLogo">
              <img :src="form.avatar" alt="">
              <span class="changText">更换头像</span>
            </div>
          </div>
        </div>
      </form>
    </div>
  </div>
</template>

<script>
import { req, API_USER_EDIT, API_USER_FINDBYID, API_AUTH_FANSNUM, API_AUTH_FOLLOWSNUM } from '@/api/api'
export default {
  name: 'Setting',
  data() {
    return {
      setIndex: 1,
      form: {}
    }
  },
  created() {
    this.form = { ...this.userInfo }
  },
  methods: {
    onSave() {
      const { id, name, signture, position } = this.form
      req.addOrUpdate(API_USER_EDIT, { id, name, signture, position }).then(() => {
        req.list(API_USER_FINDBYID, { id }).then(async res => {
          const { id } = res.object
          res.object.evens = 0
          res.object.avatar = 'http://p1.music.126.net/cwgdy8pRLlrd4dy1Hi2W0Q==/19164487672742385.jpg?param=140y140'
          const res1 = await req.list(API_AUTH_FANSNUM, { id })
          const res2 = await req.list(API_AUTH_FOLLOWSNUM, { id })
          res.object.fans = res1.total
          res.object.follows = res2.total
          this.$store.commit('SET_USERINFO', res.object);
          localStorage.setItem("music-userInfo", JSON.stringify(res.object))
          this.$message.success('修改成功')
        })
      })
    }
  },
  computed: {
    userInfo() {
      return this.$store.state.user.userInfo
    }
  }
}
</script>

<style lang="less" scoped>
.active {
  border-top: 3px solid rgb(194, 12, 12);
  border-right: 1px solid rgb(212, 212, 212);
  border-left: 1px solid rgb(212, 212, 212);
  background-color: rgb(250, 250, 250);
}

.setContent {
  width: 980px;
  // height: 580px;
  background-color: rgb(255, 255, 255);
  margin: 0 auto;

  .content {
    width: 900px;
    height: 500px;
    // background-color: antiquewhite;
    margin: 0 auto;
    padding: 40px;

    .cTitle {
      border-bottom: none;
      height: 40px;

      h3 {
        float: left;
        font-size: 24px;
        font-weight: normal;

        span {
          font-family: "Microsoft Yahei", Arial, Helvetica, sans-serif;
        }
      }
    }

    .tabs {
      height: 39px;
      border: 1px solid rgb(212, 212, 212);
      background-color: rgb(248, 248, 248);

      li {
        position: relative;
        left: -1px;
        float: left;
        width: 138px;
        height: 39px;
        // background-color: pink;
        font-size: 14px;
        text-align: center;

        a {
          padding-left: 2px;

          em {
            height: 37px;
            width: 134px;
            padding: 2px 2px 0 0;
            line-height: 38px;
            cursor: pointer;
            // text-align: center;
          }
        }
      }
    }
  }

  form {
    display: block;

    .frmBase {
      margin-top: 30px;

      .frm {
        height: 390px;
        margin-right: 30px;
        position: relative;

        .item {
          position: relative;
          min-height: 32px;
          margin-bottom: 10px;
          padding-left: 38px;

          label {
            display: block;
            position: absolute;
            top: 0;
            left: 0;
            width: 38px;
            line-height: 32px;
            text-align: right;
          }

          .txt {
            width: 292px;
            height: 19px;
            margin: 0;
            padding: 5px 6px 6px;
            border: 1px solid #cdcdcd;
            border-radius: 2px;
            line-height: 19px;
            box-sizing: content-box;
          }
        }

        .frmtext {
          position: relative;
          zoom: 1;
          min-height: 32px;
          margin-bottom: 10px;
          padding-left: 38px;

          .lab {
            display: block;
            position: absolute;
            top: 0;
            left: -5px;
            width: 38px;
            line-height: 32px;
            text-align: center;
            cursor: default;
          }

          .arear {
            padding-right: 14px;
            position: relative;
            zoom: 1;

            #sign {
              height: 122px;
              width: 302px;
            }

            .numCount {
              position: absolute;
              bottom: 8px;
              left: 265px;
              color: #d0d0d0;
            }
          }
        }

        .sexy {
          width: 340px;
          height: 32px;
          position: relative;
          margin-bottom: 10px;

          // padding-left: 38px;
          .lab {
            display: block;
            position: absolute;
            top: 0;
            left: 0;
            width: 38px;
            line-height: 32px;
            text-align: right;
          }

          .choose {
            padding-left: 30px;
            padding-top: 10px;

            .checkBoy {
              margin: 10px;

              // float:left;
              // margin:9px 20px 0 0;
              .boy {
                font-size: 12px;
                color: #333;
                font-family: Arial, Helvetica, sans-serif;
              }
            }
          }
        }

        .brith {
          position: relative;
          zoom: 1;
          min-height: 32px;
          margin-bottom: 10px;

          .brithDay {
            display: block;
            position: absolute;
            top: 0;
            left: 0;
            width: 38px;
            line-height: 32px;
            text-align: right;
          }

          .chooes {
            margin-left: 40px;
            position: relative;

            .chooesYear {
              width: 74px;
              height: 28px;
              text-align: center;
              border: 1px solid rgb(219, 219, 219);
              border-radius: 3px;
            }

            .chooesMonth {
              width: 60px;
              height: 28px;
              text-align: center;
              border: 1px solid rgb(219, 219, 219);
              border-radius: 3px;
            }

            .chooesDay {
              width: 60px;
              height: 28px;
              text-align: center;
              border: 1px solid rgb(219, 219, 219);
              border-radius: 3px;
            }
          }
        }

        .area {
          position: relative;
          zoom: 1;
          min-height: 32px;
          margin-bottom: 10px;

          .chooseArea {
            display: block;
            position: absolute;
            top: 0px;
            left: 0;
            width: 38px;
            line-height: 32px;
            text-align: right;
          }

          .Region {
            margin-left: 40px;
            position: relative;

            .chooesProvice {
              width: 74px;
              height: 28px;
              text-align: center;
              border: 1px solid rgb(219, 219, 219);
              border-radius: 3px;
            }

            .chooesCity {
              width: 74px;
              height: 28px;
              text-align: center;
              border: 1px solid rgb(219, 219, 219);
              border-radius: 3px;
            }
          }
        }

        .changLogo {
          position: absolute;
          top: 2px;
          left: 380px;

          img {
            width: 140px;
            height: 140px;
          }

          .changText {
            position: absolute;
            width: 140px;
            height: 26px;
            background-color: rgba(164, 157, 157, 0.8);
            text-align: center;
            line-height: 26px;
            bottom: 2px;
            left: 0px;
            color: white;
            cursor: pointer;
          }
        }
      }
    }
  }
}

.savebtn {
  width: 100px;
  height: 100px;
  margin-top: 40px;
  margin-left: 40px;
}

.el-button--primary {
  width: 80px;
  height: 31px;
  background-color: rgb(82, 152, 218);
  line-height: 6px;
  padding: 0 5 px 0 0;
  cursor: pointer;
}
</style>